﻿using System;
using System.IO;

namespace FtpWorkerRole.AzureStorage
{
    class AzureFile : IFile
    {
        public MemoryStream File { get; set; }
        public int Read(byte[] data)
        {
            if (File == null)
            {
                return 0;
            }
            try
            {
                return File.Read(data, 0, data.Length);
            }
            catch (IOException)
            {
                return 0;
            }
        }
        public int Write(byte[] data, int size)
        {
            if (File == null)
            {
                File = new MemoryStream();
            }
            try
            {
                File.Write(data, 0, size);
                return size;
            }
            catch (IOException)
            {
                return 0;
            }
        }

        public void Close()
        {
            if (File != null)
            {
                try
                {
                    File.Close();
                }
                catch (IOException)
                {
                }
                File = null;
            }
        }
    }
}
